package com.kepler.social.domain.support.media.converter;

import com.kepler.social.domain.support.media.vo.FileSliceMergeRsVo;
import com.kepler.social.domain.support.media.vo.FileSliceVo;
import com.kepler.social.domain.support.media.vo.M3u8Vo;

public class MediaConverter {

    /**
     * @param title
     * @param m3u8Url
     * @param poster
     * @return
     */
    public static M3u8Vo toM3u8Vo(String title, String m3u8Url, String poster) {
        return M3u8Vo.builder().title(title).m3u8Url(m3u8Url).poster(poster).build();
    }

    /**
     * 合并视频成功
     *
     * @param sliceVo
     * @param m3u8
     * @return
     */
    public static FileSliceMergeRsVo toVideoSliceMergeRsVo(FileSliceVo sliceVo, M3u8Vo m3u8) {
        return toBaseFileSliceMergeRsVo(sliceVo)
                .success(true)
                .m3u8Video(m3u8)
                .build();
    }

    /**
     * 合并图片成功
     *
     * @param sliceVo
     * @param imageUrl
     * @return
     */
    public static FileSliceMergeRsVo toImageSliceMergeRsVo(FileSliceVo sliceVo, String imageUrl) {
        return toBaseFileSliceMergeRsVo(sliceVo)
                .success(true)
                .imageUrl(imageUrl)
                .build();
    }

    /**
     * 合并失败
     *
     * @param sliceVo
     * @param message
     * @return
     */
    public static FileSliceMergeRsVo toFailureSliceMergeRsVo(FileSliceVo sliceVo, String message) {
        return toBaseFileSliceMergeRsVo(sliceVo)
                .success(false)
                .build();
    }

    /**
     * 合并结果基础信息
     *
     * @param sliceVo
     * @return
     */
    private static FileSliceMergeRsVo.FileSliceMergeRsVoBuilder toBaseFileSliceMergeRsVo(FileSliceVo sliceVo) {
        return FileSliceMergeRsVo.builder()
                .fileName(sliceVo.getFileName())
                .seqNo(sliceVo.getSeqNo())
                .mimeType(sliceVo.getMimeType());
    }

}
